<template>
  <div id="bing" style="width: 100%; height: 150%"></div>
</template>

<script>
//新增、死亡情况饼图
import request from "../utils/request";

export default {
  name: "Test-bing",
  data() {
    return {
      dataList: "",
      heal: "",
      dead: "",
    };
  },
  methods: {
    getData() {
      setInterval(() => {
        request.get("/cov/f1").then((res) => {
          this.dataList = res;
          this.heal = this.dataList[0].heal;
          this.dead = this.dataList[0].dead;
          this.initEcharts();
        });
      }, 3000);
    },
    initEcharts() {
      var chartDom = document.getElementById("bing");
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: "治愈、死亡情况饼图",
          left: "center",
          textStyle: {
            color: "#fff",
          },
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
          textStyle: {
            color: "#fff"
          }
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: "80%",
            data: [
              {value: this.heal, name: "治愈"},
              {value: this.dead, name: "死亡"},
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };

      myChart.setOption(option);
    },
  },
  mounted() {
    this.getData();
  },
};
</script>

<style scoped>
</style>
